﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LWJ_Tp_final.Models;
using WebMatrix.WebData;
using System.ComponentModel.DataAnnotations;


namespace LWJ_Tp_final_Administracion.Controllers
{
    public class UsuarioController : Controller
    {
       private DataContext BaseDeDatos = new DataContext();

        public ActionResult Index()
        {
            return View(BaseDeDatos.Usuarios.ToList());
        }

        [HttpGet]
        public ActionResult Agregar()
        {
            return View();
        }
        
        [HttpPost]
        public ActionResult Agregar(Registro usuario)
        {
            if (ModelState.IsValid)
            {
                WebSecurity.CreateUserAndAccount(usuario.UserName, usuario.Password);
                return RedirectToAction("Index");
            }
            return View("Agregar", model: usuario);
        }

    }

    public class Registro
    {
        [Required]
        public string UserName { get; set; }
        [Required]
        [MinLength(5)]
        public string Password { get; set; }
    }
}


